<template>
  <van-pull-refresh v-model="isLoading" @refresh="refresh">
    <van-list
      v-if="bol"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多数据了"
      @load="getData"
    >
      <div class="article-list">
        <article-item :item="i" v-for="i in list" :key="i.art_id" />
      </div>
    </van-list>
  </van-pull-refresh>
</template>
<script>
import ArticleItem from './article-item.vue'
import { Articles } from '@/api/home.js'
export default {
  name: 'ArticleList',
  props: ['id'],
  components: {
    ArticleItem
  },
  data () {
    return {
      bol: true,
      loading: false,
      finished: false,
      isLoading: false,
      list: [],
      timestamp: Date.now()
    }
  },
  created () {
    // this.getData()
  },
  methods: {
    async getData () {
      //   console.log(123)
      const res = await Articles({
        channel_id: this.id,
        timestamp: this.timestamp
      })
      console.log('数据：', res)
      this.list.push(...res.data.results)
      this.loading = false
      if (res.data.pre_timestamp) {
        this.timestamp = res.data.pre_timestamp
      } else {
        this.finished = true
      }
    },
    async refresh () {
      this.loading = false
      this.finished = false
      this.timestamp = Date.now()
      this.list = []
      await this.getData()
      this.isLoading = false
      this.bol = false
      this.$nextTick(() => {
        this.bol = true
      })
    }
  }
}
</script>
<style scoped lang="less">
.article-list {
  height: 100%;
  overflow-y: auto;
  padding: 0 16px;
}
::v-deep .van-list__finished-text {
  margin-bottom: 100px;
}
</style>
